{% extends './layout/default' %}

{% block breadcrumbs %}
    {{ Breadcrumbs.render(Route.getCurrentRoute.getName, tag, start, end) }}
{% endblock %}

{% block content %}
    <div class="row">
        <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'meta_data'|_ }}</h3>


                    <div class="box-tools pull-right">
                        <div class="btn-group">
                            <button class="btn btn-box-tool dropdown-toggle" data-toggle="dropdown"><span
                                    class="fa fa-ellipsis-v"></span></button>
                            <ul class="dropdown-menu" role="menu">
                                <li><a href="{{ route('tags.edit',tag.id) }}"><span
                                            class="fa fa-pencil fa-fw"></span> {{ trans('firefly.edit_tag',{tag: tag.tag}) }}
                                    </a></li>
                                <li><a href="{{ route('tags.delete',tag.id) }}"><span
                                            class="fa fa-trash fa-fw"></span> {{ trans('firefly.delete_tag',{tag: tag.tag}) }}
                                    </a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="box-body no-padding">
                    <table class="table table-bordered">
                        {% if tag.description %}
                            <tr>
                                <td>
                                    {{ trans('list.description') }}
                                </td>
                                <td>{{ tag.description }}</td>
                            </tr>
                        {% endif %}
                        {% if tag.date %}
                            <tr>
                                <td>
                                    {{ trans('list.date') }}
                                </td>
                                <td>
                                    {{ tag.date.isoFormat(monthAndDayFormat) }}
                                </td>
                            </tr>
                        {% endif %}

                        {# total amount #}
                        {% set currentSum = 0 %}
                        {% for set in sums %}
                            {% set currentSum = currentSum + set.Withdrawal + set.Transfer + set.Deposit %}
                        {% endfor %}

                        {% if currentSum != 0 %}
                            <tr>
                                <td style="width:40%;">{{ trans('list.sum') }}</td>
                                <td>
                                    {% for set in sums %}
                                        {{ formatAmountBySymbol(set.Withdrawal + set.Transfer + set.Deposit, set.currency_symbol, set.currency_decimal_places, true) }}{% if loop.index != sums|length %},{% endif %}
                                    {% endfor %}
                                </td>
                            </tr>
                        {% endif %}

                        {# total expense excl. transfer #}
                        {% set currentSum = 0 %}
                        {% for set in sums %}
                            {% set currentSum = currentSum + set.Withdrawal + set.Deposit %}
                        {% endfor %}
                        {% if currentSum != 0 %}
                            <tr>
                                <td style="width:40%;">{{ trans('list.sum_excluding_transfers') }}</td>
                                <td>
                                    {% for set in sums %}
                                        {{ formatAmountBySymbol(set.Withdrawal + set.Deposit, set.currency_symbol, set.currency_decimal_places, true) }}{% if loop.index != sums|length %},{% endif %}
                                    {% endfor %}
                                </td>
                            </tr>
                        {% endif %}

                        {# withdrawals #}
                        {% set currentSum = 0 %}
                        {% for set in sums %}
                            {% set currentSum = currentSum + set.Withdrawal %}
                        {% endfor %}
                        {% if currentSum != 0 %}
                            <tr>
                                <td style="width:40%;">{{ trans('list.sum_withdrawals') }}</td>
                                <td>
                                    {% for set in sums %}
                                        {{ formatAmountBySymbol(set.Withdrawal, set.currency_symbol, set.currency_decimal_places, true) }}{% if loop.index != sums|length %},{% endif %}
                                    {% endfor %}
                                </td>
                            </tr>
                        {% endif %}

                        {# deposits #}
                        {% set currentSum = 0 %}
                        {% for set in sums %}
                            {% set currentSum = currentSum + set.Deposit %}
                        {% endfor %}
                        {% if currentSum != 0 %}
                            <tr>
                                <td style="width:40%;">{{ trans('list.sum_deposits') }}</td>
                                <td>
                                    {% for set in sums %}
                                        {{ formatAmountBySymbol(set.Deposit, set.currency_symbol, set.currency_decimal_places, true) }}{% if loop.index != sums|length %},{% endif %}
                                    {% endfor %}
                                </td>
                            </tr>
                        {% endif %}

                        {# transfers #}
                        {% set currentSum = 0 %}
                        {% for set in sums %}
                            {% set currentSum = currentSum + set.Transfer %}
                        {% endfor %}
                        {% if currentSum != 0 %}
                            <tr>
                                <td style="width:40%;">{{ trans('list.sum_transfers') }}</td>
                                <td>
                                    {% for set in sums %}
                                        {{ formatAmountBySymbol(set.Transfer, set.currency_symbol, set.currency_decimal_places, true) }}{% if loop.index != sums|length %},{% endif %}
                                    {% endfor %}
                                </td>
                            </tr>
                        {% endif %}

                        {# reconciliation #}
                        {% set currentSum = 0 %}
                        {% for set in sums %}
                            {% set currentSum = currentSum + set.Reconciliation %}
                        {% endfor %}
                        {% if currentSum != 0 %}
                            <tr>
                                <td style="width:40%;">{{ trans('list.sum_reconciliations') }}</td>
                                <td>
                                    {% for set in sums %}
                                        {{ formatAmountBySymbol(set.Reconciliation, set.currency_symbol, set.currency_decimal_places, true) }}{% if loop.index != sums|length %},{% endif %}
                                    {% endfor %}
                                </td>
                            </tr>
                        {% endif %}

                        {#
                        {% if sums.Transfer != 0 %}
                            <tr>
                                <td>{{ trans('list.sum_transfers') }}</td>
                                <td> {{ sums.Transfer|formatAmount }}</td>
                            </tr>
                        {% endif %}
                        {% if sums.Reconciliation != 0 %}
                            <tr>
                                <td>{{ trans('list.sum_reconciliations') }}</td>
                                <td> {{ sums.Reconciliation|formatAmount }}</td>
                            </tr>
                        {% endif %}
                        #}
                    </table>
                </div>
                <div class="box-footer">
                    <div class="btn-group btn-group-sm">
                        <a href="{{ route('tags.edit',tag.id) }}" class="btn btn-default"><span
                                class="fa fa-pencil fa-fw"></span></a>
                        <a href="{{ route('tags.delete',tag.id) }}" class="btn btn-danger"><span
                                class="fa fa-trash fa-fw"></span></a>
                    </div>
                    <p class="text-muted">
                        <small>{{ 'sums_apply_to_range'|_ }}</small>
                    </p>
                </div>
            </div>
        </div>
        <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'location'|_ }}</h3>
                    <div class="box-tools pull-right">
                        <div class="btn-group">
                            <button class="btn btn-box-tool dropdown-toggle" data-toggle="dropdown"><span
                                    class="fa fa-ellipsis-v"></span></button>
                            <ul class="dropdown-menu" role="menu">
                                <li><a href="{{ route('tags.edit',tag.id) }}"><span
                                            class="fa fa-pencil fa-fw"></span> {{ trans('firefly.edit_tag',{tag: tag.tag}) }}
                                    </a></li>
                                <li><a href="{{ route('tags.delete',tag.id) }}"><span
                                            class="fa fa-trash fa-fw"></span> {{ trans('firefly.delete_tag',{tag: tag.tag}) }}
                                    </a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="box-body">
                    {% if(location) %}
                        <div id="location_map" style="width:100%;height:300px;"></div>
                    {% else %}
                        <p>{{ 'no_location_set'|_ }}</p>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
    {% if attachments.count() > 0 %}
        <div class="row">
            <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
                <div class="box">
                    <div class="box-header with-border">
                        <h3 class="box-title">
                            {{ 'attachments'|_ }}
                        </h3>
                    </div>
                    <div class="box-body no-padding">
                        {% include 'list.attachments' %}
                    </div>
                </div>
            </div>
        </div>
    {% endif %}

    {% if periods|length > 0 %}
        <div class="row">
            <div class="col-lg-offset-10 col-lg-2 col-md-offset-10 col-md-2 col-sm-12 col-xs-12">
                <p class="small text-center"><a
                        href="{{ route('tags.show',[tag.id,'all']) }}">{{ 'showEverything'|_ }}</a></p>
            </div>
        </div>
    {% endif %}
    <div class="row">
        <div class="{% if periods|length > 0 %}col-lg-10 col-md-10 col-sm-12 col-xs-12{% else %}col-lg-12 col-md-12 col-sm-12 col-xs-12{% endif %}">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'transactions'|_ }}</h3>


                    <div class="box-tools pull-right">
                        <div class="btn-group">
                            <button class="btn btn-box-tool dropdown-toggle" data-toggle="dropdown"><span
                                    class="fa fa-ellipsis-v"></span></button>
                            <ul class="dropdown-menu" role="menu">
                                <li><a href="{{ route('tags.edit',tag.id) }}"><span
                                            class="fa fa-pencil fa-fw"></span> {{ trans('firefly.edit_tag',{tag: tag.tag}) }}
                                    </a></li>
                                <li><a href="{{ route('tags.delete',tag.id) }}"><span
                                            class="fa fa-trash fa-fw"></span> {{ trans('firefly.delete_tag',{tag: tag.tag}) }}
                                    </a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="box-body">
                    {% include 'list.groups' with {showBudget:true, showCategory: true} %}

                    {% if periods|length > 0 %}
                        <p>
                            <span class="fa fa-calendar"></span>
                            <a href="{{ route('tags.show', [tag.id,'all']) }}">
                                {{ 'show_all_no_filter'|_ }}
                            </a>
                        </p>
                    {% else %}
                        <p>
                            <span class="fa fa-calendar"></span>
                            <a href="{{ route('tags.show', [tag.id]) }}">
                                {{ 'show_the_current_period_and_overview'|_ }}
                            </a>
                        </p>
                    {% endif %}
                </div>
            </div>
        </div>
        {% if periods|length > 0 %}
            <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12">
                {% include 'list.periods' %}
            </div>
        {% endif %}
    </div>
    {% if periods|length > 0 %}
        <div class="row">
            <div class="col-lg-offset-10 col-lg-2 col-md-offset-10 col-md-2 col-sm-12 col-xs-12">
                <p class="small text-center"><a href="{{ route('tags.show',[tag.id]) }}">{{ 'showEverything'|_ }}</a>
                </p>
            </div>
        </div>
    {% endif %}

{% endblock %}
{% block styles %}
    <link rel="stylesheet" href="v1/lib/leaflet/leaflet.css?v={{ FF_VERSION }}"/>
{% endblock %}
{% block scripts %}
    <script type="text/javascript" nonce="{{ JS_NONCE }}">
        // location stuff
        {% if location %}
        var latitude = {{ location.latitude|default("52.3167") }};
        var longitude = {{ location.longitude|default("5.5500") }};
        var zoomLevel = {{ location.zoom_level|default("6") }};
        {% endif %}
    </script>
    <script src="v1/lib/leaflet/leaflet.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
    <script src="v1/js/ff/tags/show.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
    <script type="text/javascript" src="v1/js/ff/list/groups.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
{% endblock %}
